//
//  AskQuestionsSuccessfulVC.m
//  OnionHome
//
//  Created by fengjie on 2019/9/17.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "AskQuestionsSuccessfulVC.h"
#import "UserIconAndNameView.h"
#import "FriendsListController.h"

@interface AskQuestionsSuccessfulVC ()
/**listViewTool*/
@property (nonatomic,strong)UITableViewTool*listViewTool;
/**数据源*/
@property (nonatomic,strong)NSMutableArray*dataSoure;

/**头部视图*/
@property (nonatomic,strong)AskQuestionsSuccessfulHeaderView*headerView;
/**尾部视图*/
@property (nonatomic,strong)AskQuestionsSuccessfulFootView*footView;
@end

@implementation AskQuestionsSuccessfulVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"提问成功";
    [self createUI];
}
-(void)backBtnClicked{
    [self.navigationController popToRootViewControllerAnimated:YES];
}
-(void)createUI{
    [self.listViewTool.listView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
}
-(void)pushFriendsList{
    [self.navigationController pushViewController:[FriendsListController new] animated:YES];
}
-(UITableViewTool*)listViewTool{
    if(!_listViewTool){
        _listViewTool=[[UITableViewTool alloc] initWithFrame:CGRectZero style:UITableViewStylePlain registerCellClassName:NSStringFromClass([AskQuestionsSuccessCell class]) identifier:NSStringFromClass([AskQuestionsSuccessCell class]) dataArray:self.dataSoure delegate:self dataSourceBlock:^(id  _Nonnull TempCell, NSIndexPath * _Nonnull indexPath, id  _Nonnull TempData) {
            
        } selectCell:^(id  _Nonnull TempCell, NSIndexPath * _Nonnull indexPath, id  _Nonnull TempData) {
            
        }];
        
        _listViewTool.listView.tableHeaderView = self.headerView;
        _listViewTool.listView.tableFooterView = self.footView;

    }
    return _listViewTool;
}
-(NSMutableArray *)dataSoure{
    if (!_dataSoure) {
        
        _dataSoure =[[NSMutableArray alloc] initWithObjects:@"",@"",@"",@"", nil];
    }
    return _dataSoure;
}
-(AskQuestionsSuccessfulHeaderView*)headerView{
    if(!_headerView){
        _headerView=[[AskQuestionsSuccessfulHeaderView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 290)];
    }
    return _headerView;
}
-(AskQuestionsSuccessfulFootView*)footView{
    if(!_footView){
        _footView=[[AskQuestionsSuccessfulFootView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 40)];
        _footView.userInteractionEnabled = YES;
        [_footView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushFriendsList)]];
    }
    return _footView;
}
@end


@interface AskQuestionsSuccessfulHeaderView ()
/**用户视图*/
@property (nonatomic,strong)UserIconAndNameView*userView;
/**标题*/
@property (nonatomic,strong)UILabel*titleLabel;
/**描述*/
@property (nonatomic,strong)UILabel*describeLb;
/**回答、收藏视图*/
@property (nonatomic,strong)AnswerCollectionView*answerView;

@end

@implementation AskQuestionsSuccessfulHeaderView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}
-(void)createUI{
    
    UIView * line = UIView.new;
    line.backgroundColor = UIColorFromRGB(0xF5F7F5);
    
    UIImageView * imageView = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"selectImage_select")];
    
    UILabel * label1 = [UILabel new];
    label1.text = @"提问成功";
    label1.font = SYSTEMFONT(16);
    label1.textColor = UIColorFromRGB(0x454F44);
    
    UILabel *label2 = UILabel.new;
    label2.text = @"你可以邀请下面用户来更快获得回答";
    label2.font = SYSTEMFONT(12);
    label2.textAlignment = NSTextAlignmentCenter;
    label2.textColor = UIColorFromRGB(0x959E97);

    [self addSubview:self.userView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.describeLb];
    [self addSubview:self.answerView];
    [self addSubview:line];
    
    [self addSubview:imageView];
    [self addSubview:label1];
    [self addSubview:label2];
    
    [self.userView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(self.userView.mas_bottom).offset(16);
    }];
    [self.describeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(8);
    }];
    
    [self.answerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(self.describeLb.mas_bottom).offset(25);
    }];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(8);
        make.top.mas_equalTo(self.answerView.mas_bottom).offset(26);
    }];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(label1.mas_left).offset(-5);
        make.height.with.mas_equalTo(20);
        make.top.mas_equalTo(line.mas_bottom).offset(10);
    }];
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(5);
        make.top.mas_equalTo(line.mas_bottom).offset(10);
    }];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(label1.mas_bottom).offset(4);
    }];

    

}

#pragma mark ---懒加载

-(UserIconAndNameView*)userView{
    if(!_userView){
        _userView=[[UserIconAndNameView alloc] initWithFrame:CGRectZero];
        _userView.deleButton.hidden= YES;
    }
    return _userView;
}
-(UILabel*)titleLabel{
    if(!_titleLabel){
        _titleLabel=[UILabel new];
        _titleLabel.textColor = UIColorFromRGB(0x273323);
        _titleLabel.font = SYSTEMFONT(18);
        _titleLabel.text = @"西红柿炒蛋先放西红柿还是先放鸡蛋？";
    }
    return _titleLabel;
}
-(UILabel*)describeLb{
    if(!_describeLb){
        _describeLb=[UILabel new];
        _describeLb.textColor = UIColorFromRGB(0x454F44);
        _describeLb.font = SYSTEMFONT(14);
        _describeLb.text =@"每次炒的男朋友都不喜欢吃，想问问大家是怎么做的？顺序是先放鸡蛋还是先放西红柿？";
        _describeLb.numberOfLines=2;
    }
    return _describeLb;
}
-(AnswerCollectionView*)answerView{
    if(!_answerView){
        _answerView=[[AnswerCollectionView alloc] initWithFrame:CGRectZero];
        
    }
    return _answerView;
}
@end


@interface AnswerCollectionView ()
/**回答*/
@property (nonatomic,strong)UILabel*oneLabel;
/**收藏*/
@property (nonatomic,strong)UILabel*twoLabel;
/**邀请回答*/
@property (nonatomic,strong)UIButton*thereBtn;
@end

@implementation AnswerCollectionView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}
-(void)createUI{
    [self addSubview:self.oneLabel];
    [self addSubview:self.twoLabel];
    [self addSubview:self.thereBtn];
    
    [self.oneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.centerY.mas_equalTo(0);
    }];
    [self.twoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.oneLabel.mas_right).offset(20);
        make.centerY.mas_equalTo(0);
    }];
    [self.thereBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.mas_equalTo(0);
    }];

}

#pragma mark --懒加载

-(UILabel*)oneLabel{
    if(!_oneLabel){
        _oneLabel=[UILabel new];
        _oneLabel.textColor = UIColorFromRGB(0x959E97);
        _oneLabel.font = SYSTEMFONT(12);
        _oneLabel.text = @"暂无回答";
    }
    return _oneLabel;
}
-(UILabel*)twoLabel{
    if(!_twoLabel){
        _twoLabel=[UILabel new];
        _twoLabel.textColor = UIColorFromRGB(0x959E97);
        _twoLabel.font = SYSTEMFONT(12);
        _twoLabel.text = @"暂无回答";
    }
    return _twoLabel;
}
-(UIButton*)thereBtn{
    if(!_thereBtn){
        _thereBtn=[UIButton new];
        [_thereBtn setTitle:@"邀请回答" forState:UIControlStateNormal];
        [_thereBtn setTitleColor:UIColorFromRGB(0x454F44) forState:UIControlStateNormal];
        [_thereBtn setImage:IMAGE_NAMED(@"邀请回答") forState:UIControlStateNormal];
        _thereBtn.titleLabel.font = SYSTEMFONT(14);
        kWeakSelf(weakSelf);
        [_thereBtn addActionHandler:^{
            [[weakSelf getCurrentViewController].navigationController pushViewController:[FriendsListController new] animated:YES];
        }];
    }
    return _thereBtn;
}
@end

@implementation AskQuestionsSuccessfulFootView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = UIColorFromRGB(0xF5F7F5);
        self.userInteractionEnabled = YES;
        
        CustomButton * button = [CustomButton buttonWithHorizontalTitle:@"查看更多" Image:@"more" imageIsLeft:NO];
        button.titleColor =UIColorFromRGB(0x959E97);
        button.titleFont = SYSTEMFONT(14);
        button.userInteractionEnabled = YES;
        kWeakSelf(weakSelf);
        button.handler = ^(CustomButton * _Nonnull view) {
            [[weakSelf getCurrentViewController].navigationController pushViewController:[FriendsListController new] animated:YES];
        };
        [self addSubview:button];
        
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(0);
        }];
    }
    return self;
}

@end

@interface AskQuestionsSuccessCell ()
/**用户头像*/
@property (nonatomic,strong)UIImageView*iconImage;
/**用户名称*/
@property (nonatomic,strong)UILabel*userName;
/**类别*/
@property (nonatomic,strong)UILabel*categoryLb;
/**按钮*/
@property (nonatomic,strong)UIButton*rightBtn;

@end

@implementation AskQuestionsSuccessCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createUI];
    }
    return self;
}
-(void)createUI{
    [self addSubview:self.iconImage];
    [self addSubview:self.userName];
    [self addSubview:self.categoryLb];
    [self addSubview:self.rightBtn];
    
    [self.iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.width.height.mas_equalTo(40);
        make.bottom.mas_equalTo(-16);
        make.top.mas_equalTo(16);
    }];
    [self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.iconImage.mas_right).offset(12);
        make.top.mas_equalTo(self.iconImage);
        
    }];
    [self.categoryLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.userName);
        make.bottom.mas_equalTo(self.iconImage);

    }];
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-16);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(30);
    }];
}
-(UIImageView*)iconImage{
    if(!_iconImage){
        _iconImage=[UIImageView new];
        _iconImage.backgroundColor = KGrayColor;
        _iconImage.layer.cornerRadius = 20;
        _iconImage.layer.masksToBounds = YES;
        _iconImage.image = IMAGE_NAMED(@"user5");
    }
    return _iconImage;
}
-(UILabel*)userName{
    if(!_userName){
        _userName=[UILabel new];
        _userName.textColor = UIColorFromRGB(0x273323);
        _userName.font = SYSTEMFONT(16);
        _userName.text =@"我是大鲨鱼";
    }
    return _userName;
}
-(UILabel*)categoryLb{
    if(!_categoryLb){
        _categoryLb=[UILabel new];
        _categoryLb.textColor = UIColorFromRGB(0x959E97);
        _categoryLb.font = SYSTEMFONT(14);
        _categoryLb.text =@"知名美食达人";
    }
    return _categoryLb;
}
-(UIButton*)rightBtn{
    if(!_rightBtn){
        _rightBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        [_rightBtn setTitle:@"邀请" forState:UIControlStateNormal];
        [_rightBtn setTitle:@"邀请" forState:UIControlStateDisabled];
        [_rightBtn setBackgroundImage:[UIImage createImageWithColor:UIColorFromRGB(0x009966)] forState:UIControlStateNormal];
        [_rightBtn setBackgroundImage:[UIImage createImageWithColor:UIColorFromRGB(0xF5F7F5)] forState:UIControlStateDisabled];
        [_rightBtn setTitleColor:UIColorFromRGB(0xFFFFFF) forState:UIControlStateNormal];
        [_rightBtn setTitleColor:UIColorFromRGB(0x959E97) forState:UIControlStateDisabled];
        
        _rightBtn.titleLabel.font = SYSTEMFONT(14);
        
    }
    return _rightBtn;
}

@end
